package bank.main;

import bank.support.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author Mathew Lowery
 * @version 1.0
 */

public class Bank {
  private BankAccount[] accounts;
  private int accountCount;

  public Bank(int accountCapacity) {
    accounts = new BankAccount[accountCapacity];
  }

  public int openNewAccount(String customerName, double openingBalance) {
    BankAccount newAccount = new BankAccount(customerName, openingBalance);
    accounts[accountCount++] = newAccount;
    return newAccount.getAccountNumber();
  }

  public void withdrawFrom(int accountNumber, double amount) {
    boolean found = false;
    for (int i = 0; i < accountCount; i++) {
      if (accounts[i].getAccountNumber() == accountNumber) {
        accounts[i].withdraw(amount);
        found = true;
      }
    }
    if (found == false) {
      System.out.println("Could not find account specified.");
    }
  } // withdrawFrom

  public void depositTo(int accountNumber, double amount) {
    boolean found = false;
    for (int i = 0; i < accountCount; i++) {
      if (accounts[i].getAccountNumber() == accountNumber) {
        accounts[i].deposit(amount);
        found = true;
      }
    }
    if (found == false) {
      System.out.println("Could not find account specified.");
    }
  } // depositTo

  public void printAccountInfo(int accountNumber) {
    boolean found = false;
    for (int i = 0; i < accountCount; i++) {
      if (accounts[i].getAccountNumber() == accountNumber) {
        System.out.println(accounts[i].getAccountInfo());
        found = true;
      }
    }
    if (found == false) {
      System.out.println("Could not find account specified.");
    }
  } // printAccountInfo

  public void printAccountInfo(int accountNumber, int lastNTransactions) {
    boolean found = false;
    for (int i = 0; i < accountCount; i++) {
      if (accounts[i].getAccountNumber() == accountNumber) {
        System.out.println(accounts[i].getAccountInfo());
        System.out.println(accounts[i].getTransactionInfo(lastNTransactions));
        found = true;
      }
    }
    if (found == false) {
      System.out.println("Could not find account specified.");
    }
  } // printAccountInfo
} // Bank